package com.rd.teacher.jichao.day01;

import java.util.Arrays;
import java.util.Objects;

public class ObjectTest {

    public static void main(String[] args) {
//        Person p1 = new Person("Tony");
//        Person p2 = new Person("Tony");
        // 使用 ==  比较的是地址
//        System.out.println(p1 == p2);
//        System.out.println(p1.equals(p2));
        // 使用 equals  比较对象的值
//        System.out.println(p1);

        int[] arr = {1,2,3};
        System.out.println(arr);
        System.out.println(Arrays.toString(arr));

    }
}

class Person {
    private String name;

    public Person(String name) {
        this.name = name;
    }

//    @Override
//    public boolean equals(Object obj){
//        return false;
//    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        // 这里不适用 instanceof
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(name, person.name);
    }


    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    @Override
    public String toString() {
        return name;
    }
}
